using System;

using Azure.Domain.Processors;

using Xunit;

namespace Azure.Tests.Domain.Processors
{
    public class BaseProcessorFacts : Facts<BaseProcessorFacts.TestProcessor>
    {
        [Fact]
        public void ConstructorSetsInitialized()
        {
            Assert.Equal(ProcessorState.Initialized, ClassUnderTest.State);
        }

        [Fact]
        public void ProcessorCanBeStarted()
        {
            ClassUnderTest.Start();

            Assert.Equal(ProcessorState.Running, ClassUnderTest.State);
        }

        [Fact]
        public void ProcessorCanBeStopped()
        {
            ClassUnderTest.Stop();

            Assert.Equal(ProcessorState.Stopped, ClassUnderTest.State);
        }

        [Fact]
        public void DisposeSetsUninitialized()
        {
            ClassUnderTest.Dispose();

            Assert.Equal(ProcessorState.Uninitialized, ClassUnderTest.State);
        }

        [Fact]
        public void StartCannotBeRunAfterDisposed()
        {
            ClassUnderTest.Dispose();

            Assert.Throws<InvalidOperationException>(() => ClassUnderTest.Start());
        }

        [Fact]
        public void StopCannotBeRunAfterDisposed()
        {
            ClassUnderTest.Dispose();

            Assert.Throws<InvalidOperationException>(() => ClassUnderTest.Stop());
        }

        public class TestProcessor : BaseProcessor
        {
            protected override void OnStart()
            {
            }

            protected override void OnStop()
            {
            }
        }
    }
}